<div id="tb<?php echo $uniqid;?>" style="padding:5px">
	<table cellspacing="0" cellpadding="0">
		<tbody>
		<tr>
			<td><a href="javascript:void(0);" onclick="MerchantStoreMemberlistReload();" class="l-btn l-btn-small l-btn-plain"><span
					class="l-btn-left l-btn-icon-left"><i class="iconfont icon-shuaxin"></i><span
					class="l-btn-text">重载</span></span></a></td>
			<td>
				<select id="MerchantStoreMemberlistKeywordsType" class="forminput inputstyle textbox-text validatebox-text" style="width:80px">
					<option value="id">会员ID</option>
					<option value="nickname">会员昵称</option>
					<option value="phone">手机号</option>
				</select></td>
			<td><input id="MerchantStoreMemberlistKeywords" style="width:120px" type="text"
					   class="easyui-input textbox"></td>
			<td><a href="javascript:void(0);" onclick="MerchantStoreMemberlistSearch();" class="l-btn l-btn-small l-btn-plain"><span
					class="l-btn-left l-btn-icon-left"><i class="iconfont icon-sousuo"></i><span
					class="l-btn-text">查询</span></span></a></td>
		</tr>
		</tbody>
	</table>
</div>
<div class="con"  style="-moz-user-select:none;">
	<table id="MerchantStoreMemberTable"></table>
</div>
<script>
	var MerchantStoreMemberlistReload = function () {
		$("#MerchantStoreMemberTable").datagrid('reload');
	};
	var MerchantStoreMemberlistSearch = function () {
		$("#MerchantStoreMemberTable").datagrid({
			title: '',
			width: 798,
			height: 538,//高度
			singleSelect: false,//如果为true，则只允许选择一行
			striped: true,//是否显示斑马线效果。
			rownumbers: false,//如果为true，则显示一个行号列。
			pagination: true,//是否显示分页
			pageSize: 10,
			pageList: [10, 15, 20, 25],
			method: 'post',
			sortName: 'id',
			sortOrder: 'desc',
			idField: 'id',
			url: '/merchant/store/getmemberlist',
			queryParams: {
				keywordsType: $('#MerchantStoreMemberlistKeywordsType').val(),
				keywords: $('#MerchantStoreMemberlistKeywords').val(),
			},
			fitColumns: true,//真正的自动展开/收缩列的大小，以适应网格的宽度，防止水平滚动。
			nowrap: true,//如果为true，则在同一行中显示数据。设置为true可以提高加载性能。 是否换行
			selectOnCheck: true,
			checkOnSelect: true,
			toolbar: '#tb<?php echo $uniqid;?>',
			columns: [[
				{field: 'checkbox', title: 'checkbox', checkbox:'true', width: fixWidth(10)},
				{field: 'id', title: 'ID', width: fixWidth(10)},
				{field: 'avatar', title: '头像', width: fixWidth(10), formatter: function (value, rowData, rowIndex) {
					return value ? "<img height='30px' src='" + value + "'>" : '';
				}},
				{field: 'nickname', title: '用户昵称', width: fixWidth(25)},
				{field: 'phone', title: '手机号', width: fixWidth(25)},
				{field: 'level_info', title: '身份', width: fixWidth(20), formatter(value, rowData) {
					return value.length ? value.name : '普通会员';
				}},
			]],
			onLoadSuccess: function (data){
				if(data.total && data.rows.length && 'undefined' !== typeof MerchantStoreEditVm && MerchantStoreEditVm.member_ids.length){
					$.each(data.rows, function(key, row) {
						if($.inArray(row.id, MerchantStoreEditVm.member_ids) > -1){
							$("#MerchantStoreMemberTable").datagrid('checkRow', key);
						}else{
							$("#MerchantStoreMemberTable").datagrid('uncheckRow', key);
						}
					});
				}

			}
		});
	};
	MerchantStoreMemberlistSearch();
	$('#MerchantStoreMasterSubmit').click(function (data) {
		var rows = $('#MerchantStoreMemberTable').datagrid('getChecked');
		if (rows.length) {
			for (let i = 0; i<rows.length; i++){
				if($.inArray(rows[i].id, MerchantStoreEditVm.member_ids) === -1){
					MerchantStoreEditVm.member_ids.push(rows[i].id);
					MerchantStoreEditVm.member_names.push({id:rows[i].id, name:rows[i].nickname});
				}
			}
		}
		$("#MerchantStoreEditdlg").dialog('close');
	});
</script>
